/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package entityBeans;

import java.io.Serializable;
import java.util.Collection;

import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author user
 * 
 *
 */
@Entity
@Table(name = "ability")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Ability.findAll", query = "SELECT a FROM Ability a"),
    @NamedQuery(name = "Ability.findByAId", query = "SELECT a FROM Ability a WHERE a.aId = :aId"),
    @NamedQuery(name = "Ability.findByName", query = "SELECT a FROM Ability a WHERE a.name = :name"),
    @NamedQuery(name = "Ability.findByDescription", query = "SELECT a FROM Ability a WHERE a.description = :description")})
public class Ability implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "A_ID")
	protected String aId;
    //@Size(max = 20)
    @Column(name = "Name")
    private String name;
    //@Size(max = 40)
    @Column(name = "Description")
    private String description;
    public String getAccepted() {
		return accepted;
	}

	public void setAccepted(String accepted) {
		this.accepted = accepted;
	}

	@Column(name = "Accepted")
	protected String accepted;
    

	@JoinTable(name = "able", joinColumns = {
        @JoinColumn(name = "A_ID", referencedColumnName = "A_ID")}, inverseJoinColumns = {
        @JoinColumn(name = "User_ID", referencedColumnName = "User_ID")})
    @ManyToMany
    private Collection<User> userCollection;

    public Ability() {
    }

    public Ability(String aId) {
        this.aId = aId;
    }

    public Ability(Class<Ability> class1) {
		// TODO Auto-generated constructor stub
	}

	public String getAId() {
        return aId;
    }

    public void setAId(String aId) {
        this.aId = aId;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }
    

    @XmlTransient
    public Collection<User> getUserCollection() {
        return userCollection;
    }
    //this method wrtten by Ozkan for the case 
    //when a user gain an ability
    //we will call this method
    //to add this user to ability's user list
    public void addUserToCollection(User user){
    	userCollection.add(user);
    	
    }

    public void setUserCollection(Collection<User> userCollection) {
        this.userCollection = userCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (aId != null ? aId.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Ability)) {
            return false;
        }
        Ability other = (Ability) object;
        if ((this.aId == null && other.aId != null) || (this.aId != null && !this.aId.equals(other.aId))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "swimtwo.entityBeans.Ability[ aId=" + aId + " ]";
    }
    
}